/**
 * 详情对话框
 */
var VocsEmissionInfoDlg = {
    data: {
        companyId: "",
        emissionWay: "",
        emissionProcess: "",
        delFlag: "",
        createTime: ""
    }
};

layui.extend({
    tinymce: '../../tinymce/tinymce'
}).use(['form', 'admin','upload', 'ax','tinymce'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var tinymce = layui.tinymce;
    var upload = layui.upload;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/vocsEmission/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('vocsEmissionForm', result.data);
    $("#emissionProcessDetail").attr("value",result.data.emissionProcess);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/vocsEmission/editItem", function (data) {
            if(data.code == 200) {
                Feng.success("更新成功！");
            }else{
                Feng.error("更新失败！" + data.message)
            }

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("更新失败！" + data.message)
        });
        // data.field.emissionProcess = tinymce.get('#emissionProcess').getContent();
        data.field.emissionProcess = $('#emissionProcess').val();
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //from表单提交 插入data中

    //
    // tinymce.init({
    //     elem: "#emissionProcess",
    //     height: 500,
    //     plugins:
    //         "link lists image code table colorpicker textcolor wordcount contextmenu",
    //     toolbar:
    //         "bold italic underline strikethrough | fontsizeselect | fontselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent blockquote | undo redo | link unlink image code | removeformat",
    //     branding: false,
    //     images_upload_handler: function (blobInfo, success, failure) {
    //         var file = new FormData();
    //         file.append('file', blobInfo.blob(), blobInfo.filename());
    //         $.ajax({
    //             //图片/文件上传地址
    //             url: Feng.ctxPath+'/ali/uploadFile',
    //             type: "post",
    //             data: file,
    //             processData: false,
    //             contentType: false,
    //             success: function(data) {
    //                 success(data.data);
    //             },
    //             error: function(e) {
    //                 alert("图片上传失败");
    //             }
    //         });
    //     }
    // });

    //计算过程
    var uploadInst = upload.render({
        elem: '#emissionProcessClick',
        url: Feng.ctxPath+'/ali/uploadFile',
        accept:'file'

        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                loading = layer.load(0, {
                    shade: false,
                    time: 10*1000
                })
            });
        }
        ,done: function(res){
            console.log(res);
            layer.close(loading);
            $('#emissionProcess1').attr('value', res.data);

            $('#emissionProcess').attr("value", res.data);
            Feng.success("上传成功" )
            // $("#flowChartImg").after('<input type="hidden" name="flowChart" value="' + res.data + '" />');
            //上传成功
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#emissionProcess1');
            layer.close(loading);
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a '+'class="layui-btn layui-btn-xs demo-reload">重试</ a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });

});